<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //实例化xhr对象
    const xhr = new XMLHttpRequest()
    //调用open函数
    xhr.open('GET', 'http://liulongbin.top:3006/api/getbooks')
    //调用send函数
    xhr.send()
    //监听readystatechange事件
    xhr.addEventListener('readystatechange', function () {
      //this.readyState === 4 && this.status === 200 判断请求是否成功，固定写法
      if (this.readyState === 4 && this.status === 200) {
        //获取服务器响应数据
        console.log(this.responseText)
      }
    })
  </script>
</body>

</html>